package offer;

/**
 * @Author Elephas
 * @Date 2022/1/30
 **/
@FunctionalInterface
public interface JudgeCycle {
    boolean judgeCircle(String moves);
}
class JudgeCycleImpl1 implements JudgeCycle{

    @Override
    public boolean judgeCircle(String moves) {
        char[] movesArray = moves.toCharArray();
        int upOffset = 0,rightOffset = 0;
        for (int i = 0; i < movesArray.length; i++) {
            char cur = movesArray[i];
            switch (cur){
                case 'U': upOffset++; break;
                case 'D': upOffset--; break;
                case 'L': rightOffset--; break;
                case 'R': rightOffset++; break;
            }
        }
        if(upOffset == 0 && rightOffset ==0){
            return true;
        }else{
            return false;
        }
    }
}
